<?php
	defined('_JEXEC') or die('Restricted access');
    require_once(CUTEENGINE_BASE_COMPONENTS_PATH."base_tag_class.php");
	require_once(CUTEENGINE_NAMESPACES_PATH."javascript_namespace.php");
    /********** 
            t_moving_and_sizing_tags
            
         **********/
	class t_moving_and_sizing_tags extends t_base_tag
	{	
        //const declaration
		// public
        const postfix_name ='_moving_and_sizing_tags';
		// property declaration 
        // public
        // A
        public $associated_tag = false;
		// method declaration
		// public
        public function __construct($a_associated_tag,$a_visible = true) 
		{
            global $g_javascript_namespace;
            //
			parent::__construct(t_base_tag_type::btt_div,
                $a_associated_tag->name . self::postfix_name . ":base_tags");
            $this->associated_tag = $a_associated_tag;
			//javascript
 			$g_javascript_namespace->header_script_generator->add_function_to_main_scope(
                "edit_tag","e","
            if (e == null) { e = window.event; }
            var local_sender_moving_anchor = (typeof( window.event ) != \"undefined\" ) ? e.srcElement : e.target;
            
            local_moving_and_sizing_base_tag = get_moving_and_sizing_base_tag(local_sender_moving_anchor);
            local_sender = local_moving_and_sizing_base_tag.parentNode;
            local_sender_style = get_computed_style(local_sender);
            
            if (local_sender != undefined)
            {
                initialize_size_window();
                g_start_left=local_sender_style.left;
                g_start_right=local_sender_style.right;
                g_start_top=local_sender_style.top;
                g_start_bottom=local_sender_style.bottom;
                g_start_mouse_x=e.clientX;
                g_start_mouse_y=e.clientY;
            
                if (document.current_moving_and_sizing_base_tag == undefined)
                {
                    document.old_onmousedown=document.onmousedown;
                    document.onmousedown=edit_tag;
                    document.old_onmousemove = document.onmousemove;
                    document.onmousemove = do_moving_and_sizing;
                    document.old_onmouseup = document.onmouseup;
                    document.onmouseup = stop_moving_and_sizing;
                    document.current_sender_moving_anchor = local_sender_moving_anchor;
                    document.current_moving_and_sizing_base_tag_pointer_text = document.getElementById(local_moving_and_sizing_base_tag.id+'_pointer_text');
                }                
            }
            if (document.current_moving_and_sizing_base_tag == undefined)
                document.current_moving_and_sizing_base_tag = local_moving_and_sizing_base_tag;
            return false;");            
            //
            $g_javascript_namespace->header_script_generator->add_function_to_main_scope(
                "get_moving_and_sizing_base_tag","a_sender","
            local_sender = a_sender;
            if (local_sender != undefined)
            {
                local_id = local_sender.id; 
                if (local_id != undefined)
                    local_pos = local_id.indexOf(':base_tags');
            }	
            while ((local_sender != undefined) && (local_pos < 0))
            {
                local_sender = local_sender.parentNode;
                if (local_sender != undefined)
                {
                    local_id = local_sender.id; 
                    if (local_id != undefined)
                        local_pos = local_id.indexOf(':base_tags');
                }	
            }
            return local_sender;");
            //
            $g_javascript_namespace->header_script_generator->add_function_to_main_scope(
                "do_moving_and_sizing","e","
            if (e == null) { e = window.event;}
            local_moving_and_sizing_base_tag = document.current_moving_and_sizing_base_tag;
            local_sender = local_moving_and_sizing_base_tag.parentNode;
            local_sender_pointer_text = document.current_moving_and_sizing_base_tag_pointer_text;
            local_sender_moving_anchor_id = document.current_sender_moving_anchor.id;
            local_tag_type = local_sender_moving_anchor_id.substring(local_sender_moving_anchor_id.indexOf(':'));
            /**/
            if (local_tag_type == ':moving_anchor')
            {
                local_sender.style.left=add_value_to_position_value(g_start_left,sub_value_to_position_value(e.clientX,g_start_mouse_x));
                local_sender.style.top=add_value_to_position_value(g_start_top,sub_value_to_position_value(e.clientY,g_start_mouse_y));
                local_sender.style.bottom=sub_value_to_position_value(g_start_bottom,sub_value_to_position_value(e.clientY,g_start_mouse_y));
                local_sender.style.right=sub_value_to_position_value(g_start_right,sub_value_to_position_value(e.clientX,g_start_mouse_x));    
            }
            else
            {
                if ((local_tag_type == ':on_top_left_anchor') || (local_tag_type == ':on_bottom_left_anchor'))
                {
                    local_sender.style.width = '';
                    local_sender.style.height = '';
                    local_sender.style.right = g_start_right;
                    local_sender.style.left=add_value_to_position_value(g_start_left,sub_value_to_position_value(e.clientX,g_start_mouse_x));
                }    
                if ((local_tag_type == ':on_top_left_anchor') || (local_tag_type == ':on_top_right_anchor'))
                {   
                    local_sender.style.width = '';
                    local_sender.style.height = '';
                    local_sender.style.bottom = g_start_bottom;
                    local_sender.style.top=add_value_to_position_value(g_start_top,sub_value_to_position_value(e.clientY,g_start_mouse_y));
                }    
                if ((local_tag_type == ':on_bottom_left_anchor') || (local_tag_type == ':on_bottom_right_anchor'))   
                {
                    local_sender.style.width = '';
                    local_sender.style.height = '';
                    local_sender.style.top = g_start_top;
                    local_sender.style.bottom=sub_value_to_position_value(g_start_bottom,sub_value_to_position_value(e.clientY,g_start_mouse_y));
                }
                if ((local_tag_type == ':on_top_right_anchor') || (local_tag_type == ':on_bottom_right_anchor'))   
                {
                    local_sender.style.width = '';
                    local_sender.style.height = '';
                    local_sender.style.left = g_start_left;
                    local_sender.style.right=sub_value_to_position_value(g_start_right,sub_value_to_position_value(e.clientX,g_start_mouse_x));
                }
                if (local_sender_pointer_text != undefined)
                {
                    local_sender_pointer_text.innerHTML = \"left:\"+local_sender.style.left+\" - top:\"+local_sender.style.top;
                } 
                
            }    
            if (local_sender.on_resize_function != undefined)
                    local_sender.on_resize_function();
            
            return false;");
            //
            $g_javascript_namespace->header_script_generator->add_function_to_main_scope(
                "stop_moving_and_sizing","e","
            document.current_moving_and_sizing_base_tag = undefined;
            document.current_sender_moving_anchor = undefined;
            document.current_moving_and_sizing_base_tag_pointer_text = undefined;
            document.onmousedown=document.old_onmousedown;
            document.old_onmousedown=undefined;
            document.onmousemove = document.old_onmousemove;
            document.old_onmousemove = null;
            document.onmouseup = document.old_onmouseup;
            document.old_onmouseup = null;");
            // BASE TAG
			$this->class_name = "moving_and_sizing_component_class";
			if ($a_visible == false)
				$this->add_style_property("visibility","hidden");
			/*$g_javascript_namespace*/$this->header_script_generator->add_style_sheet_property(".$this->class_name","position","absolute");
			/*$g_javascript_namespace*/$this->header_script_generator->add_style_sheet_property(".$this->class_name","left","0px");
			/*$g_javascript_namespace*/$this->header_script_generator->add_style_sheet_property(".$this->class_name","top","0px");
			/*$g_javascript_namespace*/$this->header_script_generator->add_style_sheet_property(".$this->class_name","bottom","0px");
			/*$g_javascript_namespace*/$this->header_script_generator->add_style_sheet_property(".$this->class_name","right","0px");
			// TAG SIZE AND MOVING
			$tag_image_moving_class_name = "moving_and_sizing_tags_class_anchor";
			/*$g_javascript_namespace*/$this->header_script_generator->add_style_sheet_property(".$tag_image_moving_class_name","position","absolute");
			/*$g_javascript_namespace*/$this->header_script_generator->add_style_sheet_property(".$tag_image_moving_class_name",'background-color','orangered');
			/*$g_javascript_namespace*/$this->header_script_generator->add_style_sheet_property(".$tag_image_moving_class_name","width","32px");
			/*$g_javascript_namespace*/$this->header_script_generator->add_style_sheet_property(".$tag_image_moving_class_name","height","32px");
			/*$g_javascript_namespace*/$this->header_script_generator->add_style_sheet_property(".$tag_image_moving_class_name",'opacity', '0.15');	
            /*$g_javascript_namespace*/$this->header_script_generator->add_style_sheet_property(".$tag_image_moving_class_name",'filter','alpha(opacity=15)');
			/*$g_javascript_namespace*/$this->header_script_generator->add_style_sheet_property(".$tag_image_moving_class_name:hover",'opacity', '0.5');	
            /*$g_javascript_namespace*/$this->header_script_generator->add_style_sheet_property(".$tag_image_moving_class_name:hover",'filter','alpha(opacity=50)');
            // TAG MOVING
            $local_array =  explode(":", $this->name);
            $local_html_tag_common_name = $local_array[0];
			$local_html_tag_name = $local_html_tag_common_name.':moving_anchor';
            $local_html_tag = $this->create_and_add_child_at_bottom(t_base_tag_type::btt_div,$local_html_tag_name);
            $local_html_tag->class_name = $tag_image_moving_class_name;
			$local_html_tag->add_style_property("width","32px");
			$local_html_tag->add_style_property("height","32px");
			$local_html_tag->add_style_property("top","33px");
			$local_html_tag->add_style_property("left","0px");				
			/*$g_javascript_namespace*/$this->header_script_generator->add_style_sheet_property("#$local_html_tag_name","position","absolute");
			/*$g_javascript_namespace*/$this->header_script_generator->add_style_sheet_property("#$local_html_tag_name",'background-color','orangered');
			//$local_html_tag->add_event_as_local_method($local_html_tag->name,'onmousedown','edit_tag',$this->delayed_position,'event');
            $local_html_tag->add_property('onmousedown','edit_tag();');
			//$local_html_tag->add_property('src','image_moving.gif');
            // TAG SIZING
            // on_top_left_anchor
			$local_html_tag_name = $local_html_tag_common_name.':on_top_left_anchor';
            $local_html_tag = $this->create_and_add_child_at_bottom(t_base_tag_type::btt_div,$local_html_tag_name);
            $local_html_tag->class_name = $tag_image_moving_class_name;
			$local_html_tag->add_style_property("top","0px");
			$local_html_tag->add_style_property("left","0px");				
			//$local_html_tag->add_event_as_local_method($local_html_tag->name,'onmousedown','edit_tag',$this->delayed_position,'event');
            $local_html_tag->add_property('onmousedown','edit_tag();');
			// $local_html_tag->add_property('src','image_moving.gif');
            // on_top_right_anchor
			$local_html_tag_name = $local_html_tag_common_name.':on_top_right_anchor';
            $local_html_tag = $this->create_and_add_child_at_bottom(t_base_tag_type::btt_div,$local_html_tag_name);
            $local_html_tag->class_name = $tag_image_moving_class_name;
			$local_html_tag->add_style_property("top","0px");
			$local_html_tag->add_style_property("right","0px");				
			//$local_html_tag->add_event_as_local_method($local_html_tag->name,'onmousedown','edit_tag',$this->delayed_position,'event');
            $local_html_tag->add_property('onmousedown','edit_tag();');
			//$local_html_tag->add_property('src','image_moving.gif');
            // on_bottom_left_anchor
			$local_html_tag_name = $local_html_tag_common_name.':on_bottom_left_anchor';
            $local_html_tag = $this->create_and_add_child_at_bottom(t_base_tag_type::btt_div,$local_html_tag_name);
            $local_html_tag->class_name = $tag_image_moving_class_name;
			$local_html_tag->add_style_property("bottom","0px");
			$local_html_tag->add_style_property("left","0px");				
			//$local_html_tag->add_event_as_local_method($local_html_tag->name,'onmousedown','edit_tag',$this->delayed_position,'event');
            $local_html_tag->add_property('onmousedown','edit_tag();');
			//$local_html_tag->add_property('src','image_moving.gif');
            // on_bottom_right_anchor
			$local_html_tag_name = $local_html_tag_common_name.':on_bottom_right_anchor';
            $local_html_tag = $this->create_and_add_child_at_bottom(t_base_tag_type::btt_div,$local_html_tag_name);
            $local_html_tag->class_name = $tag_image_moving_class_name;
			$local_html_tag->add_style_property("bottom","0px");
			$local_html_tag->add_style_property("right","0px");				
			//$this->add_event_as_local_method($local_html_tag->name,'onmousedown','edit_tag',$this->delayed_position,'event',true);
            $local_html_tag->add_property('onmousedown','edit_tag();');
			//$local_html_tag->add_property('src','image_moving.gif');
        }
	}	
?>